<?php

namespace App\Http\Controllers;

use App\Agent;
use Illuminate\Http\Request;

class AgentController extends Controller
{
    public function index(Request  $request){
        $id=$request->get('id');
        if ($id){
            $agent=Agent::find($id);
        }else{
            $agent=Agent::first();
        }
    return [
        'id'=>$agent->id,
        'name'=>$agent->name,
        'avatar'=>\Storage::url($agent->avatar),
        'mobile'=>$agent->mobile,
        'mobile_format'=>substr_replace(substr_replace($agent->mobile, '-', 3, 0),'-',8,0),
        'address'=>$agent->address,
        'job'=>$agent->job

    ];
    }
}
